<script setup lang='ts'>
import { onMounted, ref } from 'vue';

const aDom = ref(null) //建立ref对象
const btnDom = ref(null)
onMounted(() => {
    if(aDom.value){
        const dom = aDom.value as HTMLAnchorElement
        dom.href = 'https://www.qq.com'
    }
    if(btnDom.value){
        const dom = btnDom.value as HTMLButtonElement
        dom.onclick = ()=>{
            alert('点我干嘛')
        }
    }
})
</script>

<template>
    <h1>获取a标签的dom对象</h1>
    <a ref="aDom" href="https://www.baidu.com">百度</a>
    <button ref="btnDom">获取button按钮</button>
</template>

<style scoped></style>

<!-- 常用命令 -->
<!-- npm run dev / npm run start -->
<!-- yarn dev -->
<!-- pnpm run dev -->